/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ManagerLogin;

import java.sql.*;
import DBManager.DBConnection;
import java.util.Date;

/**
 *
 * @author Alex
 */
public class ManagerLogin {
      public boolean LoginManager(String username, String password)
    {
        boolean result = false;

        try{
            //get connection
            DBConnection db = new DBConnection();
            Connection conn = db.getConnection();

            //Construct SQL Query
           PreparedStatement pstmt= conn.prepareStatement("SELECT * FROM manager WHERE username = ? AND password = ?");

            //append values for the parameters
            int i=1;
             pstmt.setString(i++, username);
             pstmt.setString(i++, password);



            //execute SQL statement
        ResultSet rs= pstmt.executeQuery();

            //check if there is a data inside rs

            while(rs.next())
            {
            result=true;
            }
 conn.close();
        }
        catch(SQLException ex){ex.printStackTrace();}

        return result;
    }
    
    
     public String getInfo(String username, int x)
    {

        String result= "";

        try{
            //get connection
            DBConnection db = new DBConnection();
            Connection conn = db.getConnection();

            //Construct SQL Query
           PreparedStatement pstmt= conn.prepareStatement("SELECT * FROM manager where username ='"+username+"'");

            //append values for the parameters






            //execute SQL statement
        ResultSet rs= pstmt.executeQuery();

            //check if there is a data inside rs

 while(rs.next())
 {
 result=rs.getString(x);

 }
 conn.close();
        }
        catch(SQLException ex){ex.printStackTrace();}

        return result;
    }
     
      public int getInfo2(String username, int x)
    {

        int result= 0;

        try{
            //get connection
            DBConnection db = new DBConnection();
            Connection conn = db.getConnection();

            //Construct SQL Query
           PreparedStatement pstmt= conn.prepareStatement("SELECT * FROM manager where username ='"+username+"'");

            //append values for the parameters






            //execute SQL statement
        ResultSet rs= pstmt.executeQuery();

            //check if there is a data inside rs

 while(rs.next())
 {
 result=rs.getInt(x);

 }
 conn.close();
        }
        catch(SQLException ex){ex.printStackTrace();}

        return result;
    }
     
       public int Log(int x)
    { Date newDate = new java.util.Date();
       int result=0;
        
        try{
            //get connection
            DBConnection db = new DBConnection();
            Connection conn =  db.getConnection();
             java.util.Date time = new java.util.Date();
             
            String query="insert into logmanager(mangid,message) values(?,?)";
                   String message="Manager Login date"+newDate;
                   String message1="\nManager Login time:"+time;
          
            PreparedStatement pstmt =  conn.prepareStatement("insert into logmanager(mangid,message) values(?,?)");
            
            //append values for the parameters
            int i = 1;
            pstmt.setInt(i++, x);
            pstmt.setString(i++, message);
           
            pstmt.executeUpdate();
result=1;
            //execute SQL statement
         
          
        }
        catch(SQLException ex){ex.printStackTrace();}
        
        return result;
    }  
}
